using SalesPages.DomainModel;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace SalesPages.EntityFrameworkRepository.Mapping
{
    public class ProductItemMap : EntityTypeConfiguration<ProductItem>
    {
        public ProductItemMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.ProductCode)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.CountryCode)
                .IsFixedLength()
                .HasMaxLength(2);

            this.Property(t => t.AgeGroupCode)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.RootPath)
                .IsRequired()
                .HasMaxLength(250);

            this.Property(t => t.ProductPath)
                .IsRequired()
                .HasMaxLength(250);

            this.Property(t => t.CourseCode)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("ProductItem");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.ProductCode).HasColumnName("ProductCode");
            this.Property(t => t.SortOrder).HasColumnName("SortOrder");
            this.Property(t => t.CountryCode).HasColumnName("CountryCode");
            this.Property(t => t.AgeGroupCode).HasColumnName("AgeGroupCode");
            this.Property(t => t.Blurb_id).HasColumnName("Blurb_id");
            this.Property(t => t.RootPath).HasColumnName("RootPath");
            this.Property(t => t.ProductPath).HasColumnName("ProductPath");
            this.Property(t => t.CourseCode).HasColumnName("CourseCode");
            this.Property(t => t.BeginDate).HasColumnName("BeginDate");
            this.Property(t => t.EndDate).HasColumnName("EndDate");
            this.Property(t => t.InsertDate).HasColumnName("InsertDate");
            this.Property(t => t.UpdateDate).HasColumnName("UpdateDate");
            this.Property(t => t.IsLanding).HasColumnName("IsLanding");
            this.Property(t => t.DescBlurb_id).HasColumnName("DescBlurb_id");

            // Relationships
            this.HasRequired(t => t.AgeGroup_lkp)
                .WithMany(t => t.ProductItems)
                .HasForeignKey(d => d.AgeGroupCode);

        }
    }
}
